package designpatterns.filter;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2022/2/13 9:57
 */
@Slf4j
public class AppTest {

    public static final String SINGLE = "Single";
    public static final String MARRIED = "Married";
    public static final String FEMALE = "Female";
    public static final String LAURA = "Laura";

    @Test
    public void test() {
        List<Person> persons = new ArrayList<>();

        persons.add(new Person(designpatterns.composite.AppTest.ROBERT, "Male", SINGLE));
        persons.add(new Person("John", "Male", MARRIED));
        persons.add(new Person(LAURA, FEMALE, MARRIED));
        persons.add(new Person("Diana", FEMALE, SINGLE));
        persons.add(new Person("Mike", "Male", SINGLE));
        persons.add(new Person("Bobby", "Male", SINGLE));

        Criteria male = new CriteriaMale();
        Criteria female = new CriteriaFemale();
        Criteria single = new CriteriaSingle();
        Criteria singleMale = new AndCriteria(single, male);
        Criteria singleOrFemale = new OrCriteria(single, female);

        log.info("Males: ");
        printPersons(male.meetCriteria(persons));

        log.info("Females: ");
        printPersons(female.meetCriteria(persons));

        log.info("Single Males: ");
        printPersons(singleMale.meetCriteria(persons));

        log.info("Single Or Females: ");
        printPersons(singleOrFemale.meetCriteria(persons));
    }

    public static void printPersons(List<Person> persons) {
        for (Person person : persons) {
            log.info("Person : [ Name : {}, Gender : {}, Marital Status : {} ]", person.getName(), person.getGender(), person.getMartialStatus());
        }
    }
}
